#pragma once

#include <Singleton.h>
#include <FunctionMap.h>

enum ePACKET_HANDLER
{
	PACKET_HANDLER_AGENT,
	PACKET_HANDLER_GAME,
	PACKET_HANDLER_WORLD,
	PACKET_HANDLER_MASTER,
	PACKET_HANDLER_GUILD,
	PACKET_HANDLER_MAX,
};

struct MSG_BASE;
class ServerSession;

class PacketHandler : public Singleton<PacketHandler>
{

	typedef VOID (*fnHandler)( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );

public:
	PacketHandler();
	~PacketHandler();


	BOOL				Resister();
	BOOL				AddHandler( ePACKET_HANDLER PHandler, BYTE category, BYTE protocol, fnHandler fnHandler );
	VOID				ParsePacket( ePACKET_HANDLER PHandler, ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );

private:
	struct HANDLER_FUNC : public util::BASE_FUNC
	{
		fnHandler		m_fnHandler;
	};

	util::FunctionMap	m_FuncMap[PACKET_HANDLER_MAX];
	/*
	typedef VOID (*fnHandler)( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );

public:
	PacketHandler();
	~PacketHandler();

	BOOL			ResisterHandler_DG();
	BOOL			ResisterHandler_MX();
	BOOL			ResisterHandler_AD();
	BOOL			ResisterHandler_DW();
	BOOL			ResisterHandler_DZ();

	BOOL			AddHandler_MX( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_AD( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_DG( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_DW( BYTE category, BYTE protocol, fnHandler fnHandler );
	BOOL			AddHandler_DZ( BYTE category, BYTE protocol, fnHandler fnHandler );

	VOID			ParsePacket_DG( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );
	VOID			ParsePacket_MX( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );
	VOID			ParsePacket_AD( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );
	VOID			ParsePacket_DW( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );
	VOID			ParsePacket_DZ( ServerSession * pSession, MSG_BASE *pMsg, WORD wSize );

private:
	struct FUNC_DG : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_MX : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_AD : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_DW : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};
	struct FUNC_DZ : public BASE_FUNC
	{
		fnHandler	m_fnHandler;
	};

	FunctionMap		*m_pFuncMap_DG;
	FunctionMap		*m_pFuncMap_MX;
	FunctionMap		*m_pFuncMap_AD;
	FunctionMap		*m_pFuncMap_DW;
	FunctionMap		*m_pFuncMap_DZ;
	*/
};
